public class DescribeObjectController {

   
       private Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
       public String selectedObject {get; set;}
       public List<String> entities{get; set;}
       public List<SelectOption> objNames{get;set;}
       public String SelectObject{get;set;}
       Public List<fieldvalues> allfieldnames{get;set;}
       Public List<fieldvalues> picklistfields{get;set;}       
       
       public String selectdataType{get;set;}
       
       
       public List<SelectOption> datatypes{get;set;}
       
       
       public List<string> picklistValues{get;set;}
       public  Schema.sObjectType sobject_type{get;set;}
       public  List<Schema.SObjectField> sobject_Field{get;set;}
       public Transient Schema.DescribeSObjectResult sobject_describe{get;set;}
       public Map<String, Schema.SObjectField> field_map{get;set;}
       public List<Schema.PicklistEntry> pick_list_values{get;set;}
       public Set<String> Field_Name {get;set;}
       public List<selectOption> option{get;set;}
       public List<String> values{get;set;}
       public List<Schema.DescribeFieldResult> describefields{get;set;}
       Public  Schema.DisplayType datatype{get;set;}
       Public List<fieldvalues> alldatatype{get;set;}

        
        
           public List<SelectOption> getObjectNames(){
           
              objNames = new List<SelectOption>();
              entities = new List<String>(schemaMap.keySet());
              entities.sort();
              objNames.add(new SelectOption('--Select Object--','--Select Object--'));
               for(String name :entities)
               
                   {
                       objNames.add(new SelectOption(name,name));
                   }
                
                        return objNames;
                
                }
                
                
             public List<SelectOption> getDatatypes(){
           
                      datatypes = new List<SelectOption>();  
                    

                                                            
                      datatypes.add(new SelectOption('--Select DataType--','--Select DataType--'));
                      datatypes.add(new SelectOption('STRING','STRING'));
                      datatypes.add(new SelectOption('PHONE','PHONE'));
                      datatypes.add(new SelectOption('PICKLIST','PICKLIST'));
                      datatypes.add(new SelectOption('DATE','DATE'));
                      datatypes.add(new SelectOption('TEXTAREA','TEXTAREA'));
                      datatypes.add(new SelectOption('REFERENCE','REFERENCE'));
                      datatypes.add(new SelectOption('BOOLEAN','BOOLEAN'));
                      datatypes.add(new SelectOption('DATETIME','DATETIME'));
                      datatypes.add(new SelectOption('CURRENCY','CURRENCY'));
                      datatypes.add(new SelectOption('TEXT','TEXT'));
                      datatypes.add(new SelectOption('MULTIPICKLIST','MULTIPICKLIST'));
                      
                         return datatypes;
                
                }
        
        public DescribeObjectController(){
             
             
             
             //SelectObject=getObjectNames();
              getDatatypes();
              alldatatype=new List<fieldvalues>();
              allfieldnames=new List<fieldvalues>();
              picklistfields=new List<fieldvalues>();
               
                  /*picklistValues = new List<String>();
                  sobject_type = project__c.getSObjectType();
                  sobject_describe = sobject_type.getDescribe();
                  field_map = sobject_describe.fields.getMap();
                  Field_Name=field_map.keyset();
                
                    
                
                    //describefields=project__c.sliding_doors_proper_gasketing__c.getDescribe();
                    //datatype=describefields.gettype();
                    
                   alldatatype=new List<fieldvalues>();
                   
                   alldatatype.clear();
                   for(Schema.SObjectField fil:field_map.values())
                    {
                        
                        fieldvalues fvalues=new fieldvalues();
                        
                         schema.describefieldresult results=fil.getDescribe();
                         //datatype=results.getType();
                         fvalues.Ftype=results.getType();
                         fvalues.Fname=results.getName();
                         if(results.getType()==Schema.DisplayType.MULTIPICKLIST){
                             alldatatype.add(fvalues);
                         }
                    }*/
                    
                    /*for(String s: Field_Name)
                        {
                             pick_list_values=field_map.get(s).getDescribe().getPickListValues();
                             getpicklistvalues();
                            
                        }*/
                }
                
                
             
             public void FieldDescribe()
             
                 {
                     try
                        {
                         allfieldnames.clear();
                         picklistfields.clear();
                         
                       if(SelectObject!=null)
                       {  
                         field_map=schemaMap.get(SelectObject).getDescribe().fields.getMap();                        
                         Field_Name=field_map.keyset();
                         
                      for(Schema.SObjectField fil:field_map.values())
                        {
                        
                       
                        
                            fieldvalues fvalues=new fieldvalues();
                            
                             schema.describefieldresult results=fil.getDescribe();
                             //datatype=results.getType();
                             fvalues.Ftype=results.getType();
                             fvalues.Fname=results.getName();
                             fvalues.Label=results.getLabel();
                             fvalues.Length=results.getLength();                            
                             fvalues.Precision=results.getPrecision();
                             fvalues.Scale=results.getScale();
                             
                             allfieldnames.add(fvalues);
                            
                          
                            
                            if(selectdataType!=null)
                              {
                                if(Schema.DisplayType.STRING.Name()==selectdataType)
                                  {                        
                                    if(results.getType()==Schema.DisplayType.STRING)
                                        {
                                            picklistfields.add(fvalues);
                                        
                                        }
                                   }
                                if(Schema.DisplayType.PICKLIST.name()==selectdataType)
                                  {                        
                                    if(results.getType()==Schema.DisplayType.PICKLIST)
                                        {
                                            picklistfields.add(fvalues);
                                        
                                        }
                                   }
                                   
                                 if(Schema.DisplayType.MULTIPICKLIST.name()==selectdataType)
                                  {                        
                                    if(results.getType()==Schema.DisplayType.MULTIPICKLIST)
                                        {
                                            picklistfields.add(fvalues);
                                        
                                        }
                                   }   
                              }   
                      
                       }
                       
                     }
                       
                     }catch(Exception e){
                     
                     }
                 
                 
                 }
  
                public class fieldvalues{
                
                   
                   public String Fname{get;set;}
                   public String Label{get;set;}
                   public Schema.DisplayType FType {get;set;}
                   public Integer Length {get;set;}
                   public Integer Scale {get;set;}
                   public Integer Precision {get;set;}
                      
                   public Schema.sObjectField Contriller {get;set;}
                
                }
                
                public List<selectOption> getpicklistvalues()
                    {          
                    option= new List<SelectOption>();  
                    values=new  List<String>();
                          
                         for(Schema.PicklistEntry a: pick_list_values){
                             
                                 option.add(new selectOption(a.getLabel(),a.getValue()));
                                 values.add(a.getLabel());
                                 system.debug('$$$$$$$$'+values);
                             }
                    
                        return option;
                    }
                    
                    
                    
                    
                    
                
        public String Describe(){
        
        Schema.sObjectType sobject_type = project__c.getSObjectType();
       
        return null;
        }
}